(function(){
	$(function(){
		initPages();
		window.onresize = function () {
			initPages();
		};
		pageBtns();
		getUserInfo();
	});
	function getUserInfo(){
		var seachUrl = decodeURI(window.location.search);
		var paramStr = seachUrl.substring(1);
		params = paramStr.split("&");
		var parm = {};
		for(var i = 0; i < params.length; i++){
			var key = params[i].split("=")[0];
			var value = params[i].split("=")[1];
			parm[key] = value;
		}
		for(var key in parm){
			if(parm[key] == "" || parm[key] == undefined || parm[key] == null){
				window.location.href = encodeURI("login.html");
				return false;
				break;
			}
		}
		$("#user-name").text(substr(parm.username,4)).attr("title",parm.username).attr("key",parm.userkey).attr("code",parm.usercode).attr("usertype",1).attr("schoolcode",parm.schoolcode);
		$("#user-head").attr("src","../"+ ServiceName + parm.headimg);
	}	
	function substr(str,len){
		if(str != undefined){
			if(str.length > len){
				str = str.substring(0,len-1)+"...";
				return str;
			}else{
				return str;
			}
		}else{
			return "";
		}
	}
	function initPages(){
		var winH = document.documentElement.clientHeight || document.body.clientHeight;
		var bodyH = winH - $(".index-head").height() - $(".footer").height()-5;
		$(".index-body").height(bodyH);
	}
	
	function pageBtns(){
		$(".head-menu").click(function(){
			$(".head-menu").removeClass("head-menu-select");
			if($(this).text() == "新闻公告"){
				$(this).addClass("head-menu-select");
				changePage(PageUrl.pnewsManageUrl);
			}else if($(this).text() == "位置服务"){
				$(this).addClass("head-menu-select");
				changePage(PageUrl.ppositionIndexUrl);
			}else if($(this).text() == "校务信息"){
				$(this).addClass("head-menu-select");
				changePage(PageUrl.pschoolManageUrl);
			}else if($(this).text() == "消费管理"){
				$(this).addClass("head-menu-select");
				changePage(PageUrl.pconsumeManageUrl);
			}else if($(this).text() == "终端设置"){
				$(this).addClass("head-menu-select");
				changePage(PageUrl.pterminalManageUrl);
			}
		});
		
		$(".logout-btns").click(function(){
			window.location.href = encodeURI("login.html");
		});
		
		$(".person-set-btns").click(function(){
			var usercode = $("#user-name").attr("code");
			var userKey = $("#user-name").attr("key");
			var usertype = $("#user-name").attr("usertype");
			var url = "setting.html?usercode="+usercode+"&userkey="+userKey+"&usertype="+usertype;
			window.open(url);
		});
		
		$(".user-info").mouseover(function(){
			$("#navigate").show();
		});
		
		$(".sys-menu").mouseover(function(){
			$("#navigate").hide();
		});
		
		$(".index-logo").mouseover(function(){
			$("#navigate").hide();
		});

		$(".index-body").mouseover(function(){
			$("#navigate").hide();
		});
		
		$(".logout-btns").mouseover(function(){
			$(".logout-btns").addClass("logout-btns-select");
		});
		
		$(".logout-btns").mouseout(function(){
			$(".logout-btns").removeClass("logout-btns-select");
		});
		
		$(".person-set-btns").mouseover(function(){
			$(".person-set-btns").addClass("person-set-btns-select");
		});
		
		$(".person-set-btns").mouseout(function(){
			$(".person-set-btns").removeClass("person-set-btns-select");
		});
		
		
		$(".user-info").mouseout(function(){
			$("#navigate").mouseover(function(){
				$("#navigate").show();
			});
			
			$("#navigate").mouseout(function(){
				$("#navigate").hide();
			});
		});
		$(".room-map-close").click(function(){
			$(".index-dialog-cover").hide();
			$(".room-map-dialog").hide();
		});
		
	}
	function changePage(pageurl){
		$("#pindex-body").attr("src",pageurl);
	}
})();